/*
 * appcfix.h
 *
 *  Created on: 2010/4/3
 *      Author: Administrator
 */

#ifndef APPCFIX_H_
#define APPCFIX_H_

#include "mplib.h"

#define APPC_FILE	'appc'
#define APPCNEW_FILE	'appcnew'
#define	SZ	60
#define TZ	59

/* copy header line from appc to appcnew */
void copy_header_ln()
{

	int length, , io, io2, eofflg, blank;
	char cnum[400], inp[100], clblb[8], ch1r;
	FILE *file_old, *file_new;

	char line[MAXLINE];
	/* copy header line from appc to appcnew */
	file_old = fopen(APPC, "r");
	file_new = fopen(APPCNEW_FILE, "w");
	upcnt = 0;

	if(fgets(line, MAXLINE, file_old) == 0) {
		if(feof(file))
			return ERROR;

		fputs(line, file_new );
	}
	do{	/* Get the first column of APPC file, which is length of line */
		for(io2=0; io2<6; io2++) {
			eofflg = fgetc(file_old);
			inp[io2] = eofflg;
			if(eofflg == EOF){ /* Handle error */


			}
		}
		upcnt++;
		io2 = 0;
		/* Get the content length of the length*/
		length = ctoi(inp, io2);

		/* Get the second column of APPC file, which is b^n */
		for(io2=0; io2 < 8 ; io2++){
			eofflg = fgetc(file_old);
			clbl8[io2] = eofflg;
		}/* Trim spaces*/
		for(io2=0; io2 < 2; io2++){
			eofflg = fgetc(file_old);
			ch1r[io2] = eofflg;
		}
		for(io2=0; io2<length; io2++){
			eofflg = fgetc(file_old);
			cnum[io2] = eofflg;
			if(cnum[io2] == NEWLINE)
				io2--;
			/* Trim spaces */
			for(io=0; io<16; io++){
				eofflg = fgetc(file_old);
				ch1r[io] = eofflg;
			}
		}
		/* Read newline character */
		eofflg = fgetc(file_old);
		/* Output new format to newappc */

	}while(eofflg != EOF);

}
#endif /* APPCFIX_H_ */
